<?php
// 论坛分区控制器
namespace Admin\Controller;
use Think\Controller;

class PartController extends BaseController
{
    // 分区列表页面
    public function index()
    {
        $list = M('Part')->select();
        $this->assign('list', $list);
        $this->display();
    }

    // 新增分区页面
    public function create()
    {
        $this->display();
    }

    // 接收新增分区信息
    public function add()
    {
        $res = M('Part')->add(I('post.'));
        if($res > 0) {
            $this->success('新增分区成功', U('Part/index'));
        } else {
            $this->error('新增分区失败');
        }
    }

    // 修改分区页面
    public function edit()
    {
        $pid = I('get.pid');
        $info = M('Part')->find($pid);
        $this->assign('info', $info);
        $this->display();
    }

    public function update()
    {
        $pid = I('post.pid');

        $res = M('Part')->where(['pid' => $pid])->save(I('post.'));

        if(!$res) {
            $this->error('分区信息更更新失败');
        } else {
            $this->success('分区信息更新成功', U('Part/index'));
        }
    }

    public function delete()
    {
        $pid = I('get.pid');
        $row = M('Part')->delete($pid);
        if($row === false) {
            $this->error('分区删除失败');
        } else {
            $this->success('分区删除成功', U('Part/index'));
        }
    }
}